package event;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;

import stream.ErrorStream;

/**
 * A utility class for logging and writing error messages.
 * @author Charles
 *
 */
public class ErrorLogger extends Logger implements ErrorStream {
	public ErrorLogger(OutputStream o) {
		super(o);
	}
	
	/**
	 * Convenience method for {@link #logMsg(String)}.
	 * @param s the message to log.
	 */
	public void logErrorMsg(final String s) {
		logMsg(s);
	}
	
	/**
	 * Logs an error message based on an exception. The message logged is identical 
	 * to the string that is printed by <code>e.printSTackTrace()</code>.
	 * @param e the exception defining the error message.
	 */
	public void logErrorMsg(Exception e) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		e.printStackTrace(new PrintStream(baos));
		logErrorMsg(baos.toString());
	}

	@Override
	public void write(String s) {
		logErrorMsg(s);
	}

	@Override
	public void write(Exception e) {
		logErrorMsg(e);
	}
}
